// ====================CardEnergy====================

class CardEnergy extends Sprite {
    initialize(opts) {
        super.initialize();
        this._opts = opts;
        this._value = 0;
        this._maxValue = 0;
        this.create();
    }

    create() {
        const {width, height} = this._opts;
        const bitmap = new Bitmap(width, height);
        this.bitmap = bitmap;
    }

    getValue() {
        return CardGameManager.energy;
    }

    getMaxValue() {
        return CardGameManager.maxEnergy;
    }

    refresh() {
        const {height, fullIconIndex, emptyIconIndex} = this._opts;
        const bitmap = this.bitmap;
        bitmap.clear();
        this._value = this.getValue();
        this._maxValue = this.getMaxValue();
        let x = 0, y = (height - ImageManager.iconHeight) / 2;
        const iconIndex1 = fullIconIndex;
        const iconIndex2 = emptyIconIndex;
        for (let i = 1; i <= this._maxValue; i++) {
            if (this._value >= i) {
                bitmap.drawIcon(iconIndex1, x, y);
            } else {
                bitmap.drawIcon(iconIndex2, x, y);
            }
            x += 36;
        }
    }

    update() {
        super.update();
        if (this.getValue() !== this._value || this.getMaxValue() !== this._maxValue) {
            this.refresh();
        }
    }
}